package com.kara.woodAgent.agent.model.impl;

import com.kara.woodAgent.agent.model.ModelProvider;
import dev.langchain4j.community.model.zhipu.ZhipuAiChatModel;
import dev.langchain4j.model.chat.ChatLanguageModel;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.time.Duration;

/**
 * @author tzy
 * @version 1.0
 * @project wood_agent_base
 * @description
 * @date 2025/6/16 11:03:48
 */
@ConditionalOnProperty(prefix = "model.use",name = "enable",havingValue = "zhipu")
@Component
public class ZhipuModelProvider implements ModelProvider {

	@Value("${model.zhipu.key}")
	private String apiKey;


	@Value("${model.zhipu.name}")
	private String model;

	ZhipuAiChatModel chatModel;

	@PostConstruct
	public void init() {
		chatModel = ZhipuAiChatModel.builder()
				.apiKey(apiKey)
				.callTimeout(Duration.ofSeconds(30))
				.connectTimeout(Duration.ofSeconds(30))
				.writeTimeout(Duration.ofSeconds(30))
				.readTimeout(Duration.ofSeconds(30))
				.model(model).build();
	}

	@Override
	public ChatLanguageModel getChatModel(String type) {
		return chatModel;
	}
}
